package customer_manage_function_implementation;

import java.util.LinkedList;

import customer_manage_database.Customer;
import customer_relation_manage.Init;



public class AddCustomer {
	
	public  LinkedList<Customer> addCustomer(String[] str,LinkedList<Customer> lList){
		Customer customer=getCustomer(str);
		if (customer!=null) {
			lList.add(customer);	
		}
		else{
			System.out.println("The customer added is empty,can not add");
		}
		return lList;
	}
	
	//根据传进参数数组得到一个要Add的Customer对象
	public Customer getCustomer(String[] str){
		int iId = 0;                   //存放解析之后参数内容
		String sName = null;
		int iSex = 0;
		String sBirthday = null;
		String sAddress = null;
		String sCall = null;
		for (int i = 0; i < str.length; i++) {
			switch (str[i].substring(0,str[i].indexOf(":"))) {//得到每个数组传递的是什么信息
			case "id":
				String sId=str[i].substring(str[i].indexOf(":")+1);
				iId=Integer.parseInt(sId);
			case "name":
				sName=str[i].substring(str[i].indexOf(":")+1);
				break;
			case "sex":
				String sSex=str[i].substring(str[i].indexOf(":")+1);
				iSex=Integer.parseInt(sSex);
			    break;
			case "birthday":
				sBirthday=str[i].substring(str[i].indexOf(":")+1);
				break;
			case "address":
				sAddress=str[i].substring(str[i].indexOf(":")+1);
				break;
			case "call":
				sCall=str[i].substring(str[i].indexOf(":")+1);
				break;

			default:
				break;
			}			
		}
		Customer customer=new Customer(iId,sName,iSex,sBirthday,sAddress,sCall);
		return customer;
	}


}
